package com.example.controller;

import com.example.common.Result;
import com.example.pojo.Address;
import com.example.service.AddressService;
import lombok.extern.slf4j.Slf4j;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.web.bind.annotation.*;

@Slf4j
@RestController
@RequestMapping("/address")
public class AddressController {

    @Autowired
    private AddressService addressService;

//    添加收获地址
    @PostMapping()
    public Result addAddress(@RequestBody Address address){
       addressService.add(address);
        return Result.success();
    }

//    删除收获地址
    @DeleteMapping("/{id}")
    public Result deleteAddress(@PathVariable String id){
        addressService.delete(id);
        return Result.success();
    }

//    修改收获地址
    @PutMapping("/{id}")
    public Result updateAddress(@PathVariable("id") Integer id,  @RequestBody Address address){
        // 设置 ID 到传入的对象中
        address.setId(id);
        addressService.updateAddress(address);
        return Result.success();
    }

    //查看收货地址
    @GetMapping("/list")
    public Result getAddress(@RequestParam("empId") Integer empId){
        System.out.println("从前端拿到的empId: " +empId);
//        log.info("empId:{}",empId);
        Address address = addressService.selectAddress(empId);
        return Result.success(address);
    }
}
